<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>File handling</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('page_user_guide_kvfile.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">File handling </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#section_user_guide_kvfile_overview">Overview</a></li>
<li class="level1"><a href="#section_user_guide_kvfile_enumerate_files">Enumerate files</a></li>
<li class="level1"><a href="#section_user_guide_kvfile_copying_files_to_device">Copying files from / to device</a></li>
<li class="level1"><a href="#section_user_guide_kvfile_deleting_files">Deleting files</a></li>
<li class="level1"><a href="#section_user_guide_kvfile_disk_formatting">Disk formatting</a></li>
</ul>
</div>
<div class="textblock"><h1><a class="anchor" id="section_user_guide_kvfile_overview"></a>
Overview</h1>
<p>The file handling API can be used to manage the SD-card content of a device with t-script capablility. It allows listing files, copying files to and from the device, deleting files and formatting the SD-card (FAT32).</p>
<h1><a class="anchor" id="section_user_guide_kvfile_enumerate_files"></a>
Enumerate files</h1>
<p>The file system of the SD-card is flat, meaning the files are indexed and stored in sequential order. The functions available for checking the content of the SD-card are <a class="el" href="canlib_8h.html#a6f7e3b5d2faf2556a40ec7818cd74c47">kvFileGetCount()</a>, which as the name states retrieves the number of files on the SD-card, and <a class="el" href="canlib_8h.html#ad6ffe54a4c22dbdde855e5c8dd0634fa">kvFileGetName()</a> which retrieves the filename based on its index. With these the file content of the SD-card can be enumerated.</p>
<p><b>Example:</b> Enumerate SD-card content.</p>
<div class="fragment"><div class="line"><span class="keywordtype">char</span> buf[64];</div><div class="line"></div><div class="line">stat = <a class="code" href="canlib_8h.html#a6f7e3b5d2faf2556a40ec7818cd74c47">kvFileGetCount</a>(hnd, &amp;fileCount);</div><div class="line"><span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i &lt; fileCount; i++){</div><div class="line">    stat = <a class="code" href="canlib_8h.html#ad6ffe54a4c22dbdde855e5c8dd0634fa">kvFileGetName</a>(hnd, i, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;%3d: %s\n&quot;</span>, i, buf);</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="section_user_guide_kvfile_copying_files_to_device"></a>
Copying files from / to device</h1>
<p>Files can be copied to the device using the function <a class="el" href="canlib_8h.html#a17b1093e1d294442635e5899120c548e">kvFileCopyToDevice()</a>. Note that since the SD-card is formated using FAT32, a 8.3 formated filename as the target filename should be used. The device only allows flat file structure so no folders can be passed.</p>
<p><b>Example:</b> Copying files to device. </p><div class="fragment"><div class="line"><span class="comment">// Copy file to device.</span></div><div class="line"><span class="comment">// Separator &quot;/&quot; allowed on windows</span></div><div class="line">stat = <a class="code" href="canlib_8h.html#a17b1093e1d294442635e5899120c548e">kvFileCopyToDevice</a>(hnd, <span class="stringliteral">&quot;path/to/file1.txt&quot;</span>, <span class="stringliteral">&quot;file1.txt&quot;</span>);</div></div><!-- fragment --><p>To instead copy files from the device, use <a class="el" href="canlib_8h.html#a95f4a1383f8be77e74ff48d8be71aecf">kvFileCopyFromDevice()</a>.</p>
<p><b>Example:</b> Copying files from the device. </p><div class="fragment"><div class="line"><span class="comment">// Copy file from device.</span></div><div class="line"><span class="comment">// Separator &quot;/&quot; allowed on windows.</span></div><div class="line">stat = <a class="code" href="canlib_8h.html#a95f4a1383f8be77e74ff48d8be71aecf">kvFileCopyFromDevice</a>(hnd, <span class="stringliteral">&quot;file1.txt&quot;</span>, <span class="stringliteral">&quot;path/to/new_file.txt&quot;</span>);</div></div><!-- fragment --><h1><a class="anchor" id="section_user_guide_kvfile_deleting_files"></a>
Deleting files</h1>
<p>To delete files, use <a class="el" href="canlib_8h.html#a5430e6449f86509bb380672ee4183cc9">kvFileDelete()</a> and pass the name of the file on the SD-card.</p>
<p><b>Example:</b> Deleting files from device. </p><div class="fragment"><div class="line"><span class="comment">// Delete file from SD-card</span></div><div class="line">stat = <a class="code" href="canlib_8h.html#a5430e6449f86509bb380672ee4183cc9">kvFileDelete</a>(hnd, <span class="stringliteral">&quot;file1.txt&quot;</span>);</div></div><!-- fragment --><h1><a class="anchor" id="section_user_guide_kvfile_disk_formatting"></a>
Disk formatting</h1>
<p>To reformat the SD-card, use <a class="el" href="canlib_8h.html#a40ce4dc39d01e0d33f4a1a8590e60a9d">kvFileDiskFormat()</a>. Full initialization can be done with the kvmlib function <a class="el" href="group__kvm__disk__operations.html#gaea656874540da1c4551dbac178052647">kvmDeviceFormatDisk()</a>. <b>Example:</b> Formatting the SD-card. </p><div class="fragment"><div class="line"><span class="comment">// Format SD-card to FAT32</span></div><div class="line">stat = <a class="code" href="canlib_8h.html#a40ce4dc39d01e0d33f4a1a8590e60a9d">kvFileDiskFormat</a>(hnd);</div></div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="group__kvm__disk__operations.html#gaea656874540da1c4551dbac178052647">kvmDeviceFormatDisk()</a> </dd></dl>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_canlib.html">CAN bus API (CANlib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
